package com.dream.cgomall.controller;

import com.dream.cgomall.entity.CgoDiscover;
import com.dream.cgomall.service.CgoDiscoverService;
import com.dream.cgomall.service.impl.ContentServiceImpl;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * (CgoDiscover)表控制层
 *
 * @author makejava
 * @since 2021-07-04 11:10:06
 */
@RestController
@RequestMapping("cgoDiscover")
public class CgoDiscoverController {
    /**
     * 服务对象
     */
    @Resource
    private CgoDiscoverService cgoDiscoverService;
    @Resource
    private ContentServiceImpl contentService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public CgoDiscover selectOne(Integer id) {
        return this.cgoDiscoverService.queryById(id);
    }

    @GetMapping("selectAll")
    public List<CgoDiscover> selectAll() {
        return this.cgoDiscoverService.selectAll();
    }

    @RequestMapping("addDiscover")
    public int addDiscover(@RequestBody CgoDiscover cgoDiscover) throws IOException {
        CgoDiscover cgoDiscover1 = cgoDiscoverService.insert(cgoDiscover);
        contentService.parseContent();
        if (cgoDiscover1 != null) {
            return 1;
        } else {
            return 0;
        }
    }
}
